package com.ywx;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.stereotype.Component;

import java.util.Random;

/**
 * Created by benjamin on 2017/4/26.
 */
@Component
public class CallDependencyServie {
    private Random random = new Random();

    @HystrixCommand(fallbackMethod = "fallback")
    public String mockGetUserInfo(){
        int randomInt = random.nextInt(10);
        if(randomInt < 8){
            throw new RuntimeException("call dependency service fail.");
        }else{
            return "UserName:;number:" + randomInt;
        }
    }

    public String fallback(){
        return "some exception occur call fallback method.";
    }
}
